layui.use(['laydate','form','table','gcate'], function(){
	var laydate = layui.laydate;
	var form = layui.form;
	var table = layui.table;
	var gcate = layui.gcate;
	var user_sn = $('input[name="user_sn"]').val()
	//执行一个laydate实例
	laydate.render({
	  	elem: '#start' //指定元素
	});

	//执行一个laydate实例
	laydate.render({
	  	elem: '#end' //指定元素
	});
	/*@初始化table*/
	var tableObj = table.render({
	    elem: '#table-list',
	    url: '/user/consult/index', //数据接口
	    page: true, //开启分页
	    where: {user_sn: user_sn},
	    // where: {u_type:'新客'},
	    cols: [[ //表头
	    	{field: 'consult_goods_id', title: '序号'},
	    	{field: 'addtime', title: '咨询时间'},
	    	{field: 'username', title: '客户'},
	    	{field: 'phone', title: '联系方式'},
	    	{field: 'user_sn', title: '客户编号'},
	    	{field: 'goods_name', title: '产品名称'},
	    	{field: 'is_stock_text', title: '是否有货'},
	    	{title: '操作', width: 100,toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'查看详情\',\'/user/consult/details/ids/{{d.order_consult_id}}\')">查看详情</a></div>'},
	    ]]
	});
	
	/*@查询*/
	form.on('submit(search)',function(data){
		console.log(data)
		if(data.field.start != '' && data.field.end != ''){
			var startDate = new Date(data.field.start).getTime();
			var endDate = new Date(data.field.end).getTime();
			if(startDate > endDate){
				layer.msg('开始时间不能大于结束时间',{icon: 2})
				return false
			}
		}
		tableObj.reload({
			page: {
                page: 1 //重新从第 1 页开始
            },
            where: data.field
        });
        return false
	})
	/*@产品分类*/
	gcate.form.g_cate('select', '/staff/goods/sun_cate')
});